package com.hgyc.mom.base.controller;

import com.hgyc.mom.base.entity.MaterialType;
import com.hgyc.mom.base.service.MaterialTypeService;
import com.hgyc.mom.base.vo.MaterialTypeParam;
import com.hgyc.mom.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 物料类型信息 前端控制器
 * </p>
 *
 * @author fwj
 * @since 2025-03-24
 */
@RestController
@RequestMapping("/base/type")
public class MaterialTypeController {

    @Autowired
    private MaterialTypeService materialTypeService;

    @Operation(summary = "查询产品类型树列表", description = "查询产品类型树列表")
    @PostMapping("/treeList")
    public Result<List<MaterialType>> treeList(MaterialTypeParam materialTypeParam) {
        List<MaterialType> list = materialTypeService.treeList(materialTypeParam);
        return Result.success(list);
    }

    @Operation(summary = "获取物料类型信息详细信息", description = "获取物料类型信息详细信息")
    @GetMapping(value = "/{id}")
    public Result getInfo(@Parameter(description = "物料类型信息ID") @PathVariable("id") Long id)
    {
        return Result.success(materialTypeService.getById(id));
    }

    @Operation(summary = "新增物料类型信息", description = "新增物料类型信息")
    @PostMapping
    public Result save(@Parameter(description = "物料类型信息") @RequestBody MaterialType materialType)
    {
        materialTypeService.addNode(materialType);
        return Result.success();
    }

    @Operation(summary = "修改物料类型信息", description = "修改物料类型信息")
    @PutMapping
    public Result update(@Parameter(description = "物料类型信息") @RequestBody MaterialType materialType)
    {
        return Result.success(materialTypeService.updateById(materialType));
    }

    @Operation(summary = "删除物料类型信息", description = "删除物料类型信息")
    @DeleteMapping
    public Result remove(@Parameter(description = "删除ID") @RequestParam("ids") Long[] ids)
    {
        return Result.success(materialTypeService.removeByIds(Arrays.asList(ids)));
    }
}
